//
//  BatchController.m
//  BatchElor
//
//  Created by Luke van der Hoeven on 1/15/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "BatchController.h"

@implementation BatchController

@synthesize fileArray;

-(IBAction)getBatchFile:(id)sender {
	NSOpenPanel *panel = [NSOpenPanel openPanel];
	fileArray = [[NSMutableArray arrayWithCapacity:1] retain];
	
	int result = [panel runModal];
	if(result == NSOKButton) {
		NSString *file = [panel filename];
		[batchFile setStringValue:file];
		
		NSString *fileContents = [NSString stringWithContentsOfFile:file];
		NSEnumerator *lines = [[fileContents componentsSeparatedByString:@"\n"] objectEnumerator];
		NSString *enumLine;
		
		while(enumLine = [lines nextObject]) {
			[fileArray addObject:enumLine];
			NSLog(@"Data: %@", enumLine);
		}
	}
}

-(IBAction)setOutLocation:(id)sender {
	NSOpenPanel *panelGet = [NSOpenPanel openPanel];
	[panelGet setCanChooseDirectories:TRUE];
	[panelGet setCanChooseFiles:FALSE];
	
	int result = [panelGet runModal];
	if(result == NSOKButton) {
		NSString *file = [panelGet filename];
		[outputLocation setStringValue:file];
		[batcher setOutDir:file];
	}
}

-(IBAction)start:(id)sender {
	
	[thread1 setStringValue:[[[fileArray objectAtIndex:0] componentsSeparatedByString:@"/"] lastObject]];
	[batcher downloadFiles:self filePath:[fileArray objectAtIndex:0]];

}

-(IBAction)stop:(id)sender {
	
}

@end
